package cn.edu.jnu.x2021100733;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button buttonCaclulate = this.findViewById(R.id.button_caculate);
        EditText editTextScores = this.findViewById(R.id.edittext_frame_scores);
        TextView textViewScore = this.findViewById(R.id.textview_score);
        buttonCaclulate.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onClick(View v) {
                String scores = editTextScores.getText().toString();
                String []arrayScore = scores.split(",");
                BowlingGame bowlingGame = new BowlingGame();
                for(int i = 0;i < arrayScore.length;++i){
                    bowlingGame.roll(Integer.parseInt(arrayScore[i]));
                }
                textViewScore.setText("Total Score is : "+bowlingGame.score());
            }
        });
    }
}